package 面向对象.day04;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Graphics;

/**
 * @author 王敬仟
 * World 整个游戏
 */
public class World extends JPanel{
    //设置游戏窗口的宽 静态的不可改变的
    public static final int WIDTH=641;
    //设置游戏窗口的高 静态的不可改变的
    public static final int HEIGHT=479;
    //准备战舰
    private Battleship ship=new Battleship();
    //准备海洋对象数组
    private SeaObject[] submarines={
            new MineSubmarine(),//鱼雷潜艇
            new ObserverSubmarine(),//侦查潜艇
            new TorpedoSubmarine()//水雷潜艇
    };
    //准备鱼雷
    private Mine[] mines={
      new Mine(245,163)
    };
    //准备炸弹
    private Bomb[] bombs={
            new Bomb(165,163)
    };
    //往游戏窗口中画对象
    public void paint(Graphics g){
        //画海洋图
        Iamges.sea.paintIcon(null,g,0,0);
        //跟中海洋图 并画出海洋图
        ship.paintImage(g);
        //便利海洋潜艇对象
        for (int i=0;i<submarines.length; ++i){
            //画潜艇对象
            submarines[i].paintImage(g);
        }
        //便利所有的炸弹
        for (int i = 0; i < this.bombs.length; ++i){
            //画炸弹
            bombs[i].paintImage(g);
        }
        //便利所有的鱼雷
        for (int i = 0; i < mines.length; ++i){
            //画鱼雷
            mines[i].paintImage(g);
        }
    }
    //画窗口
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        World world = new World();
        world.setFocusable(true);
        frame.add(world);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(WIDTH+16, HEIGHT+39);
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);
        frame.setVisible(true);
    }
}
